{extend name="base" /} {block name="body"}
<div class="right">
	<div class="rigtop">
		<span class="title">商品管理</span>
	</div>
	<div class="indrig_con orders_con">
		<div class="zizh_btnbox online_btnbox">
			<button class="zizh_btn" type="button" onclick="goods_add('{:url('shop/goods_add')}')">发布商品</button>
		</div>
		<div class="spfl_topbox clearfix">
			<form action="{:url('shop/goods')}" method="get">
			<div class="chax_rowbox clearfix">
				<div class="shxx_row clearfix">
					<div class="left">商品编号：</div>
					<div class="right clearfix">
						<input type="text" name="goods_sn" placeholder="请输入商品编号" class="chax_input" />
					</div>
				</div>
				<div class="shxx_row clearfix">
					<div class="left">商品名称：</div>
					<div class="right clearfix">
						<input type="text" name="goods_name" placeholder="请输入商品名称" class="chax_input" />
					</div>
				</div>
			</div>
			<div class="chax_rowbox clearfix">
				<div class="left shxx_row clearfix">
					<span class="level_flbt">商品分类：</span>
					<span class="level_fl {if $trade_id==0}active{/if}"><a href="{:url('agent/shop/goods')}">全部</a></span> {volist name="goods_type" id="vo"}
					<a href="{:url('agent/shop/goods',['trade_id'=>$vo.id])}"><span class="level_fl {if $trade_id==$vo.id}active{/if}">{$vo.name}</span></a>
					{/volist}
				</div>
				<div class="right shxx_row clearfix">
					<button type="button" class="htcxbtn fenlcx_btn" onclick="types_add('{:url('shop/types_add')}')">+创建分类</button>
					<button type="submit" class="htcxbtn">搜索</button>
				</div>
			</div>
			</form>
		</div>
		<div class="orders_content" style="margin-top: 0px;">
			<table class="zizh_table1">
				<thead>
					<tr>
						<th>商品编号</th>
						<th>商品名称</th>
						<th>成本价</th>
						<th>零售价</th>
						<th>库存</th>
						<th>单位</th>
						<th>商品分类</th>
						<th>发布时间</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="tbody">
					{volist name="goods_list" id="vo" empty="$empty"}
					<tr>
						<td>{$vo.goods_sn|default='0'}</td>
						<td>{$vo.goods_name|default='0'}</td>
						<td>{$vo.cost_price|default='0'}</td>
						<td>{$vo.sale_price|default='0'}</td>
						<td>{$vo.stock|default='0'}</td>
						<td>{$vo.unit|default='0'}</td>
						<td>{$vo.name|default='0'}</td>
						<td>{$vo.add_time|substr=0,10}</td>
						<td>
							{if condition="$vo.is_on_sale == 1"}
							<a href="javascript:;" onclick="shangjia('{$vo.goods_id}','2')">下架</a>
							{else /}
							<a href="javascript:;" class="gray" onclick="shangjia('{$vo.goods_id}','1')">上架</a>
							{/if} {if condition="$vo.is_recommend == 1"}
							<a href="javascript:;" onclick="tuijian('{$vo.goods_id}','2')">不推荐</a>
							{else /}
							<a href="javascript:;" onclick="tuijian('{$vo.goods_id}','1')">推荐</a>
							{/if}
							<a href="javascript:;" class="gray" onclick="goods_edit('{:url('shop/goods_edit',['goods_id'=>$vo.goods_id])}')">编辑</a>
							<a class="ajax-delete" href="{:url('agent/shop/del_goods',['goods_id'=>$vo.goods_id])}">删除</a>
						</td>
					</tr>
					{/volist}
				</tbody>
			</table>
			<div class="fenye" style="display: block;">
				{$goods_list->render()}
			</div>
		</div>
	</div>
</div>

{/block} {block name="script"}
<script>
	function types_add(url) {
		layer.open({
		  type: 2,
		  title: '创建分类',
		  shadeClose: true,
		  shade: 0.8,
		  area: ['500px', '240px'],
		  content: url
		}); 
	}
	function shangjia(id, goods_state) {
		layer.confirm('您确定要修改吗？', {
			btn: ['确定', '取消'] //按钮
		}, function() {
			$.ajax({
				url: "{:url('shop/shangjia')}",
				data: {
					id: id,
					is_on_sale: goods_state
				},
				success: function(data) {
					if(data.code == 200) {
						layer.msg('修改成功', {
							icon: 1,
							time: 1500 //2秒关闭（如果不配置，默认是3秒）
						}, function() {
							location.href = "{:url('shop/goods')}";
						});
					} else {
						layer.msg('修改失败！');
					}
				}
			})
		})
	}

	//推荐
	function tuijian(id, is_recommend) {
		layer.confirm('您确定要修改吗？', {
			btn: ['确定', '取消'] //按钮
		}, function() {
			$.ajax({
				url: "{:url('shop/tuijian')}",
				data: {
					id: id,
					is_recommend: is_recommend
				},
				success: function(data) {
					if(data.code == 200) {
						layer.msg('修改成功', {
							icon: 1,
							time: 1500 //2秒关闭（如果不配置，默认是3秒）
						}, function() {
							location.href = "{:url('shop/goods')}";
						});
					} else {
						layer.msg('修改失败！');
					}
				}
			})
		})
	}

	function chuli(status) {
		var chsub = $("input[name='chk[]']:checked").length;
		if(chsub > 0) {
			var lay = layer.confirm('确认操作?', {
				icon: 3,
				title: '提示'
			}, function(index) {
				layer.close(lay);
				var arr = new Array();
				$("input[name='chk[]']:checked").each(function() {
					var id = $(this).val();
					arr.push(id);
				})
				$.ajax({
					url: "{:url('shop/chuli')}",
					data: {
						arr: arr,
						status: status
					},
					type: "post",
					success: function(data) {
						layer.msg(data.msg);
						if(data.code == 200) {
							window.location.reload();
						}

					}
				})
			});
		} else {
			layer.msg("请选择操作对象!");
			return;
		}
	}

	//调取修改商品页面
	function goods_edit(url) {
		layer.open({
			type: 2,
			title: '编辑商品',
			shadeClose: true,
			shade: 0.8,
			area: ['70%', '90%'],
			content: url
		});
	}
	//调取新增商品页面
	function goods_add(url) {
		layer.open({
			type: 2,
			title: '发布商品',
			shadeClose: true,
			shade: 0.8,
			area: ['70%', '90%'],
			content: url
		});
	}
</script>
{/block}